package global

import (
	"fmt"
	"github.com/go-ini/ini"
)

var Conf *Config

type Config struct {
	Path    PathConfig   `ini:"path"`
	Judge   JudgeConfig  `ini:"judge"`
	Server  ServerConfig `ini:"server"`
	OssConf OssConfig    `ini:"oss"`
}

type OssConfig struct {
	EndPoint string `ini:"endpoint"`
	AK       string `ini:"ak"`
	AKSecret string `ini:"ak_secret"`
}

type ServerConfig struct {
	NsqLookUpAddr []string `ini:"nsq_lookup_addr"`
	NsqAddr       string   `ini:"nsq_addr"`
	NsqConTopic   string   `ini:"nsq_con_topic"`
	NsqProTopic   string   `ini:"nsq_pro_topic"`
	NsqChannel    string   `ini:"nsq_channel"`
	Host          string   `ini:"host"`
	Token         string   `ini:"token"`
	PprofEnable   bool     `ini:"pprof_enable"`
	PprofAddr     string   `ini:"pprof_addr"`
	OjCenterAddr  string   `ini:"ojCenter_addr"`
}

type JudgeConfig struct {
	RunUserId   int `ini:"run_user_id"`
	RunGroupId  int `ini:"run_group_id"`
	MaxCpuTime  int `ini:"max_cpu_time"`
	MaxRealTime int `ini:"max_real_time"`
	Unlimited   int `ini:"unlimited"`
}

type PathConfig struct {
	Log           string `ini:"log"`
	SubmissionDir string `ini:"submission_dir"`
	TestCaseDir   string `ini:"testcase_dir"`
	SimDir        string `ini:"sim_dir"`
	WorkDir       string `ini:"work_dir"`
	CompileLog    string `ini:"compile_log"`
}

func InitConfig() {
	Conf = &Config{}
	var err error
	err = ini.MapTo(Conf, "app.ini")
	if err != nil {
		fmt.Printf("setting.Setup, fail to parse 'conf/app.ini': %v", err)
	}
}
